/*
* StotageContaner.cpp
*
* Copyright(C) 2009, Лущик Павел aka nanoo
*
* This code is lisenced under the GPL version 2. For details see 
* LISENCE.txt
*/

#include"MyWidget.h"

StorageContaner::StorageContaner(const QString &title, QWidget *parent): QGroupBox(title,parent)
{
	layout = new QVBoxLayout();
	oct_storage = new OctLabelStorage(this);
	hex_storage = new HexLabelStorage(this);
	dec_storage = new QSpinBox(this);
	dec_storage->setAlignment(Qt::AlignRight);
	dec_storage->setWrapping(true);
	dec_storage->setToolTip(tr("Use mouse wheel to change the value"));
	layout->addWidget(oct_storage);
	layout->addWidget(hex_storage);
	layout->addWidget(dec_storage);
	b_layout = new QHBoxLayout();
	b_rar = new QPushButton(">>",this);
	b_rar->setToolTip(tr("Right shift"));
	b_ral = new QPushButton("<<",this);
	b_ral->setToolTip(tr("Left shift"));
	b_clear = new QPushButton("C",this);
	b_clear->setToolTip(tr("Clear the register"));
	b_layout->addStretch(1);
	b_layout->addWidget(b_clear);
	b_layout->addWidget(b_ral);
	b_layout->addWidget(b_rar);
	layout->addLayout(b_layout);
	layout->addStretch(1);
	
	connect(hex_storage,SIGNAL(valueChanged(int)),oct_storage,SLOT(setValue(int)));
	connect(hex_storage,SIGNAL(valueChanged(int)),dec_storage,SLOT(setValue(int)));	
	
	connect(oct_storage,SIGNAL(valueChanged(int)),hex_storage,SLOT(setValue(int)));
	connect(oct_storage,SIGNAL(valueChanged(int)),dec_storage,SLOT(setValue(int)));
	
	connect(dec_storage,SIGNAL(valueChanged(int)),hex_storage,SLOT(setValue(int)));
	connect(dec_storage,SIGNAL(valueChanged(int)),oct_storage,SLOT(setValue(int)));
	
	connect(b_rar,SIGNAL(clicked()),this,SLOT(rar()));
	connect(b_ral,SIGNAL(clicked()),this,SLOT(ral()));
	connect(b_clear,SIGNAL(clicked()),this,SLOT(clear()));
	
	dec_storage->setRange(0,0xffffff);
	setLayout(layout);
}

int StorageContaner::value(void)
{
	return dec_storage->value();
}

void StorageContaner::setValue(int a)
{
	oct_storage->setValue(a);
}

void StorageContaner::rar()
{
	int value;
	value = dec_storage->value();
	value >>= 1;
	dec_storage->setValue(value);
}

void StorageContaner::ral()
{
	int value;
	value = dec_storage->value();
	value <<= 1;
	dec_storage->setValue(value);
}

void StorageContaner::undo()
{
	
}

void StorageContaner::clear()
{
	dec_storage->setValue(0);
}
